home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / VideoFolder 1.0a / Source / MoreFiles 1.4.1 / Search.p < prev    next >
Text File  |  1995-12-21  |  7KB  |  159 lines

  1. UNIT Search;
  2.  
  3. {    Apple Macintosh Developer Technical Support                                }
  4. {                                                                            }
  5. {    IndexedSearch and the PBCatSearch compatibility function.                }
  6. {    by Jim Luther, Apple Developer Technical Support Emeritus                }
  7. {                                                                            }
  8. {    File:        Search.p                                                    }
  9. {                                                                            }
  10. {    Copyright © 1992-1995 Apple Computer, Inc.                                }
  11. {    All rights reserved.                                                    }
  12. {                                                                            }
  13. {    You may incorporate this sample code into your applications without        }
  14. {    restriction, though the sample code has been provided "AS IS" and the    }
  15. {    responsibility for its operation is 100% yours.  However, what you are    }
  16. {    not permitted to do is to redistribute the source as "DSC Sample Code"    }
  17. {    after having made changes. If you're going to re-distribute the source,    }
  18. {    we require that you make it clear in the source that the code was        }
  19. {    descended from Apple Sample Code, but that you've made changes.            }
  20.  
  21.  
  22. INTERFACE
  23.  
  24. USES
  25.     Files;
  26.  
  27. {***************************************************************************}
  28.  
  29.  
  30.     FUNCTION IndexedSearch (pb: HParmBlkPtr;
  31.                                     dirID: LongInt): OSErr;
  32. {    The IndexedSearch function performs an indexed search in and below the    }
  33. {    specified directory using the same parameters (in pb) as is passed to    }
  34. {    PBCatSearch. See Inside Macintosh: Files for a description of the        }
  35. {    parameter block.                                                        }
  36. {                                                                            }
  37. {    pb            input:    A CSParamPtr record specifying the volume to search    }
  38. {                        and the search criteria.                            }
  39. {                output:    Fields in the parameter block are returned            }
  40. {                        indicating the number of matches found, the            }
  41. {                        matches, and if the search ended with noErr, the    }
  42. {                        CatPosition record that lets you resume a search    }
  43. {                        where the last search left off.                        }
  44. {    dirID        input:    The directory to search. If fsRtDirID is passed,    }
  45. {                        the entire volume is searched.                        }
  46. {                                                                            }
  47. {    Note:    If you use a high-level debugger and use ioSearchTime to limit    }
  48. {            the length of time to run the search, you'll want to step over    }
  49. {            calls to IndexedSearch because it installs a Time Manager task.    }
  50. {            Most high-level debuggers don't deal gracefully with interrupt    }
  51. {            driven code.                                                    }
  52.  
  53.  
  54. {***************************************************************************}
  55.  
  56.  
  57.     FUNCTION PBCatSearchSyncCompat (paramBlock: HParmBlkPtr): OSErr;
  58. {    The PBCatSearchSyncCompat function uses PBCatSearch (if available) or    }
  59. {    IndexedSearch (if PBCatSearch is not available) to search a volume        }
  60. {    using a set of search criteria that you specify. It builds a list of    }
  61. {    all files or directories that meet your specifications.                    }
  62. {                                                                            }
  63. {    pb            input:    A CSParamPtr record specifying the volume to search    }
  64. {                        and the search criteria.                            }
  65. {                output:    Fields in the parameter block are returned            }
  66. {                        indicating the number of matches found, the            }
  67. {                        matches, and if the search ended with noErr, the    }
  68. {                        CatPosition record that lets you resume a search    }
  69. {                        where the last search left off.                        }
  70. {                                                                            }
  71. {    Note:    If you use a high-level debugger and use ioSearchTime to limit    }
  72. {            the length of time to run the search, you'll want to step over    }
  73. {            calls to PBCatSearchSyncCompat because it calls IndexedSearch    }
  74. {            which installs a Time Manager task. Most high-level debuggers    }
  75. {            don't deal gracefully with interrupt driven code.                }
  76.  
  77.  
  78. {***************************************************************************}
  79.  
  80.  
  81.     FUNCTION NameFileSearch (volName: StringPtr;
  82.                                     vRefNum: Integer;
  83.                                     fileName: Str255;
  84.                                     matches: FSSpecPtr;
  85.                                     reqMatchCount: LongInt;
  86.                                     VAR actMatchCount: LongInt;
  87.                                     newSearch: Boolean;
  88.                                     partial: Boolean): OSErr;
  89. {    Use NameFileSearch to search for files with a specific file name on a    }
  90. {    volume that supports PBCatSearch.                                        }
  91. {    Note: A result of catChangedErr means the catalog has changed between    }
  92. {    searches, but the search can be continued with the possiblity that you    }
  93. {    may miss some matches or get duplicate matches.  For all other results    }
  94. {    (except for noErr), the search cannot be continued.                        }
  95. {                                                                            }
  96. {    volName            input:    A pointer to the name of a mounted volume        }
  97. {                            or nil.                                            }
  98. {    vRefNum            input:    Volume specification.                            }
  99. {    fileName        input:    The name of the file to search for.                }
  100. {    matches            input:    Pointer to array of FSSpec where the match list    }
  101. {                            is returned.                                    }
  102. {    reqMatchCount    input:    Maximum number of matches to return    (the number    }
  103. {                            of elements in the matches array).                }
  104. {    actMatchCount    output: The number of matches actually returned.        }
  105. {    newSearch        input:    If true, start a new search. If false and if    }
  106. {                            vRefNum is the same as the last call to            }
  107. {                            NameFileSearch, then start searching at the        }
  108. {                            position where the last search left off.        }
  109. {    partial            input:    If the partial parameter is false, then only    }
  110. {                            files that exactly match fileName will be        }
  111. {                            found.  If the partial parameter is true, then    }
  112. {                            all file names that contain fileName will be    }
  113. {                            found.                                            }
  114.  
  115.  
  116. {***************************************************************************}
  117.  
  118.  
  119.     FUNCTION CreatorTypeFileSearch (volName: StringPtr;
  120.                                     vRefNum: Integer;
  121.                                     creator: OSType;
  122.                                     fileType: OSType;
  123.                                     matches: FSSpecPtr;
  124.                                     reqMatchCount: LongInt;
  125.                                     VAR actMatchCount: LongInt;
  126.                                     newSearch: Boolean): OSErr;
  127. {    Use CreatorTypeFileSearch to search for files with a specific creator    }
  128. {    or fileType on a volume that supports PBCatSearch.                        }
  129. {    Note: A result of catChangedErr means the catalog has changed between    }
  130. {    searches, but the search can be continued with the possiblity that you    }
  131. {    may miss some matches or get duplicate matches.  For all other results    }
  132. {    (except for noErr), the search cannot be continued.                        }
  133. {                                                                            }
  134. {    volName            input:    A pointer to the name of a mounted volume        }
  135. {                            or nil.                                            }
  136. {    vRefNum            input:    Volume specification.                            }
  137. {    creator            input:    The creator type of the file to search for.        }
  138. {                            To ignore the creator type, pass 0x00000000 in    }
  139. {                            this field.                                        }
  140. {    fileType        input:    The file type of the file to search for.        }
  141. {                            To ignore the file type, pass 0x00000000 in        }
  142. {                            this field.                                        }
  143. {    matches            input:    Pointer to array of FSSpec where the match list    }
  144. {                            is returned.                                    }
  145. {    reqMatchCount    input:    Maximum number of matches to return    (the number    }
  146. {                            of elements in the matches array).                }
  147. {    actMatchCount    output: The number of matches actually returned.        }
  148. {    newSearch        input:    If true, start a new search. If false and if    }
  149. {                            vRefNum is the same as the last call to            }
  150. {                            CreatorTypeFileSearch, then start searching at    }
  151. {                            the position where the last search left off.    }
  152.  
  153.  
  154. {***************************************************************************}
  155.  
  156.  
  157. IMPLEMENTATION
  158.  
  159. END.